<template>
  <div class="sjplatformApproveForm">
    <el-form label-width="100px">
      <el-form-item label="项目名称：">
        <span>{{ projectStore.scheduleModel.projectName }}</span>
      </el-form-item>
      <el-form-item label="计划简介：">
        <span>{{ projectStore.scheduleModel.mark }}</span>
      </el-form-item>
      <el-form-item label="计划时间：">
        <el-date-picker v-model="projectStore.scheduleModel.startTime" type="date" disabled />~<el-date-picker
          v-model="projectStore.scheduleModel.endTime" type="date" disabled />
      </el-form-item>
    </el-form>

    <!-- 任务表单开始 -->
    <div v-for="(schedule, tIndex) in projectStore.scheduleModel.tasks" :key="tIndex" class="sjplatform-form-item">
      <el-form-item :key="schedule.id" :label="'任务' + (tIndex + 1) + '：'">
        <span>{{ schedule.taskName }}</span>
      </el-form-item>
      <el-form-item label="描述：">
        <span>{{ schedule.taskName }}</span>
      </el-form-item>
      <el-form-item label="父级：" v-if="schedule.sort > 1">
        <el-select v-model="schedule.pId" disabled>
          <el-option
            v-for="r in projectStore.scheduleModel.tasks.filter(r => r.id !== schedule.id && r.sort < schedule.sort && r.taskName != '')"
            :key="r.id" :label="r.taskName" :value="r.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划时间：">
        <el-date-picker v-model="schedule.startTime" type="date" disabled />~<el-date-picker v-model="schedule.endTime"
          type="date" disabled />
      </el-form-item>
      <el-form-item label="关联需求：">
        <span>{{ schedule.rName }}</span>
      </el-form-item>
      <el-form-item label="关联功能：">
        <span>{{ schedule.fTitle }}</span>
      </el-form-item>
      <el-form-item label="负责人：">
        <span>{{ schedule.personNames }}</span>
      </el-form-item>
    </div>
    <!-- 任务表单结束 -->

    <el-form label-width="100px"  v-if="historyFileList.length > 0">
      <el-form-item label="进度文档：">
        <div class="uploadHis">
          <ul class="file-list">
            <li v-for="file in historyFileList" :key="file.objectId">
              {{ file.fileName }}
              <el-tooltip content="下载" placement="bottom" effect="light">
                <i class="download-icon" @click="fileOpeartion.downloadFile(file.objectId, file.fileName)"></i>
              </el-tooltip>
            </li>
          </ul>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { ref, defineProps, defineExpose } from 'vue';
import { useProjectTable } from "../../../hooks/ProjectManager/Start/useProjectTable";
import { useProjectSchedule } from "../../../hooks/ProjectManager/Plan/useProjectSchedule";
import { useFileOperation } from '../../../hooks/Common/useFileOperation';

let fileOpeartion = useFileOperation();
let receivedProps = defineProps(['scheduleId']);
let historyFileList = ref([]);
let { projectTable, getProjectDoc } = useProjectTable(1, 10);
let { projectStore, getScheduleDetailById, updateScheduleMainSpecificContent } = useProjectSchedule(1, 10);

getScheduleDetailById(receivedProps.scheduleId).then(() => {
  //附件
  getProjectDoc(projectStore.scheduleModel.projectId, 5).then(() => {
    historyFileList.value = projectTable.documentList;
  });
})

//更新审批状态
async function updateApproveStatus(value) {
  projectStore.scheduleModel.id = receivedProps.scheduleId;
  //评审状态更新
  if (!projectStore.scheduleModel.updateProperties) {
    projectStore.scheduleModel.updateProperties = [];
  }
  projectStore.scheduleModel.status = value;
  projectStore.scheduleModel.updateProperties.push('Status');
  await updateScheduleMainSpecificContent();
}

defineExpose({ updateApproveStatus });
</script>